$(function () {
		$(".deletebtn").on("click", deletebookfromshelf);
		getPage(1, 10);
})

function deletebookfromshelf(btn) {
		var name = $(btn).attr("name");
		$.post("/wfRead/reader/deletbookfromshelf",
				"id=" + name,
				function (data) {
						if (data.flag) {
								alert("删除成功!");

								location.reload();
						} else {
								alert(data.message);
						}
				},
				"json")
}

function getPage(currentPage, pageSize) {
		//alert(currentPage+pageSize);
		$.post("/wfRead/reader/tobookshelflist",
				"currentPage=" + currentPage + "&pageSize=" + pageSize,
				function (data) {
						var pageInfo = data.data;
						console.log(pageInfo)
						$("#novel_size").text(pageInfo.total)
						var size = pageInfo.size < 10 ? pageInfo.size : 10;
						var list = pageInfo.list;
						$(".main_div .current_page").val(pageInfo.pageNum);
						$(".main_div .all_page").text(pageInfo.pages);
						$(".main_div #books tbody").empty();
						var pref = (pageInfo.pageNum - 1) * 10
						for (let i = 0; i < size; i++) {
								var li ='<tr >\n' +
										'\t\t<td>'+(i+1)+'</td>\n' +
										'\t\t<td><a target="_blank"\n' +
										'\t\t       href="/wfRead/novel/book/'+list[i].novelName.bookName+'">'+list[i].novelName.bookName+'</a>\n' +
										'\t\t</td>\n' +
										'\t\t<td><a target="_blank"\n' +
										'\t\t      href="/wfRead/read/'+list[i].novelName.bookName+'/'+list[i].bookMark+'">'+list[i].bookMark+'</a>\n' +
										'\t\t</td>\n' +
										'\t\t<td>' + Format(list[i].novelName.updateTime, "yyyy-MM-dd HH:mm") + '</td>\n' +
										'\t\t<td>\n' +
										'\t\t\t\t<button name="'+list[i].id+'" class="deletebtn" onclick="deletebookfromshelf(this)">删除</button>\n' +
										'\t\t</td>\n' +
										'</tr>'
								$(".main_div table tbody").append(li);
						}

				}, "json")
}